import operate as ope
import run_logging as log
import time
import pyautogui

# import os
#
#
#
# # 获取当前脚本所在的目录
# current_path = os.path.dirname(os.path.abspath(__file__))
#
# # 获取当前脚本所在的项目根目录
# root_path = os.path.dirname(current_path)
#
# print("项目根目录路径：", root_path)

#
# work_image_path = 'image\\work\\'
# mon_image_path = 'image\\monitor\\'
# ope_image_path = 'image\\operate\\'
#
# ope.random_sleep(3, 0)
# if ope.find_image(work_image_path + "km.png") is not None:
#     km_positions = list(pyautogui.locateAllOnScreen(work_image_path + 'km.png', confidence=0.9))
#     print(km_positions)
#     for km_position in km_positions:
#         # 获取元素的中心坐标
#         x, y = pyautogui.center(km_position)
#         # 右键点击该元素
#         ope.click_position_with_key((x, y), 'ctrl')
#         ope.random_sleep(10, 1)
#         pyautogui.keyDown('f')
#         pyautogui.keyUp('f')
#         while ope.find_image(work_image_path + "km_locked.png") is None and ope.find_image(work_image_path + "km.png") is None:
#             break
# hkmjch = ope.find_image(work_image_path + 'hkmjch.png')
# ope.save_location(hkmjch)

#
# if ope.find_image(work_image_path + 'boss1.png') is not None:
#     # 发送消息
#     log.log('暗影天蛇boss已出现')
#     # 切换总览
#     ope.click_path_with_key(work_image_path + 'boss1.png', 'Q')
#     ope.click_image_path(work_image_path + 'ab.png')
#     ope.random_sleep(2, 1)
#     ope.click_image_path(work_image_path + 'collect.png')
#     ope.random_sleep(10, 2)
#     exit_outer_loop = False
#     while ope.find_image(work_image_path + 'boss1.png') is not None:
#         ope.random_sleep(1, 0.2)
#         while ope.find_image(
#                 work_image_path + 'collect_button.png') is not None:
#             ope.click_image_path(work_image_path + 'collect_button.png')
#             log.log('暗影天蛇boss已拾取')
#             ope.click_image_path(work_image_path + 'close_window.png')
#             exit_outer_loop = True
#             break
#         if exit_outer_loop:
#             break
#     ope.click_image_path(ope_image_path + 'station.png')
#     ope.random_sleep(1, 0)
#     ope.click_image_path(work_image_path + 'jump_to_station.png')
#     ope.random_sleep(40, 5)
#     ope.click_image_path(work_image_path + 'container.png')
#     ope.click_image(ope.find_image(work_image_path + 'collect.png'))
#     ope.click_position(500, 100)
#     ope.click_position(550, 300)
#     ope.random_sleep(2, 1)
#     pyautogui.keyDown('ctrl')
#     pyautogui.keyDown('a')
#     ope.random_sleep(0.5, 0)
#     pyautogui.keyUp('a')
#     pyautogui.keyUp('ctrl')
#     pyautogui.dragTo(1250, 250, duration=1)
#     ope.click_image_path(work_image_path + 'trans_button.png')
#     ope.click_image_path(work_image_path + 'close_window.png')
#     ope.random_sleep(1, 0)
#     ope.click_image_path(work_image_path + 'container.png')

# G:\WorkspaceMyProject\python\eveAuto\cn\vic\service\pve\image\work\boss1.png
# if ope.find_image(work_image_path + 'boss1.png') is not None:
#     # 发送消息
#     log.log('暗影天蛇boss已出现')
#     # 切换总览
#     ope.click_path_with_key(work_image_path + 'boss1.png', 'Q')
#     ope.click_image_path(work_image_path + 'ab.png')
#     ope.random_sleep(2, 1)
#     ope.click_image_path(work_image_path + 'collect.png')
#     ope.random_sleep(10, 2)
#     exit_outer_loop = False
#     while ope.find_image(work_image_path + 'boss1.png') is not None:
#         ope.random_sleep(1, 0.2)
#         while ope.find_image(
#                 work_image_path + 'collect_button.png') is not None:
#             ope.click_image_path(work_image_path + 'collect_button.png')
#             log.log('暗影天蛇boss已拾取')
#             ope.click_image_path(work_image_path + 'close_window.png')
#             exit_outer_loop = True
#             break
#         if exit_outer_loop:
#             break
#     ope.click_image_path(ope_image_path + 'station.png')
#     ope.random_sleep(1, 0)
#     ope.click_image_path(work_image_path + 'jump_to_station.png')
#     ope.random_sleep(40, 5)
#     ope.click_image_path(work_image_path + 'container.png')
#     ope.click_image(ope.find_image(work_image_path + 'collect.png'))
#     ope.click_position(500, 100)
#     ope.click_position(550, 300)
#     ope.random_sleep(2, 1)
#     pyautogui.keyDown('ctrl')
#     pyautogui.keyDown('a')
#     ope.random_sleep(0.5, 0)
#     pyautogui.keyUp('a')
#     pyautogui.keyUp('ctrl')
#     pyautogui.dragTo(1250, 250, duration=1)
#     ope.click_image_path(work_image_path + 'trans_button.png')
#     ope.click_image_path(work_image_path + 'close_window.png')
#     ope.random_sleep(1, 0)
#     ope.click_image_path(work_image_path + 'container.png')


'''from tkinter import ttk


def create_window():
    # 创建主窗口
    win = tk.Tk()
    win.title("Button and Text Area Window")

    # 设置窗口大小
    win.geometry("200x300")  # 宽 x 高

    # 创建按钮
    tk.Button(win, text='开启预警', width=10, height=2).grid(row=1, column=0, padx=5, pady=0, sticky="nsew")
    tk.Button(win, text='结束预警', width=10, height=2).grid(row=2, column=0, padx=5, pady=0, sticky="nsew")
    tk.Button(win, text='开始星带', width=10, height=2).grid(row=3, column=0, padx=5, pady=0, sticky="nsew")
    tk.Button(win, text='结束星带', width=10, height=2).grid(row=4, column=0, padx=5, pady=0, sticky="nsew")
    tk.Button(win, text='开始集会', width=10, height=2).grid(row=5, column=0, padx=5, pady=0, sticky="nsew")
    tk.Button(win, text='结束集会', width=10, height=2).grid(row=6, column=0, padx=5, pady=0, sticky="nsew")

    # 创建文本区域
    text_area = tk.Text(win, wrap=tk.WORD, width=20, height=12)  # 6 buttons * 2 (height of each button) = 12
    text_area.grid(row=0, column=1, rowspan=6, padx=5, pady=5, sticky="nsew")

    # 设置列权重，使得文本区域可以扩展
    win.grid_columnconfigure(1, weight=1)

    # 运行主循环
    win.mainloop()


if __name__ == "__main__":
    create_window()'''

"""import threading
import time


# 模拟的on_work函数
def on_work(stop_event):
    print("on_work started")
    while not stop_event.is_set():
        print("on_work is running")
        time.sleep(1)
    print("on_work stopped")


# 模拟的monitor函数
def monitor():
    print("monitor started")
    # 创建一个事件对象
    stop_event = threading.Event()

    # 创建一个线程对象，目标函数是on_work
    thread = threading.Thread(target=on_work, args=(stop_event,))

    # 启动线程
    thread.start()

    # 主线程继续执行其他任务
    print("monitor continues to run")

    # 模拟一些工作
    time.sleep(5)

    # 设置事件，通知子线程停止
    stop_event.set()

    # 等待子线程结束
    thread.join()

    print("monitor finished")


# 调用monitor函数
monitor()"""

"""import winsound
def beep():
    # 在Windows系统中发出声音报警
    i = 0
    while i < 20:
        i += 1
        winsound.Beep(2000, 500)
        winsound.Beep(1000, 500)


# 发出声音报警
beep()
"""

"""class WorkThread(threading.Thread):
    def __init__(self):
        super().__init__()
        self.should_stop = False

    def run(self):
        # 执行任务
        self.start()
        ow.on_work()

    def stop(self):
        self.should_stop = True"""
"""    import run_logging as log

work_image_path = 'image\\work\\'
mon_image_path = 'image\\monitor\\'


def boss():
        f ope.find_image(work_image_path + 'boss3.png') is not None:
        # 发送消息
        # msg.send_msg('天蛇boss')
        log.log('暗影天蛇boss已出现')
        # 切换总览
        ope.click_image(ope.find_image(work_image_path + 'overview_boss.png'))
        # ope.save_location(work_image_path + 'boss3.png')
        # ope.click_image(ope.find_image(mon_image_path + 'overview_work.png'))
        ope.click_with_key(work_image_path + 'boss3.png', 'q')
        ope.click_image_path(work_image_path + 'ab.png')
        ope.click_image_path(work_image_path + 'boss3.png')
        ope.random_sleep(2, 1)
        ope.click_image_path(work_image_path + 'collect.png')
        ope.random_sleep(10, 2)
        while ope.find_image(work_image_path + 'collect_button.png') is None:
            time.sleep(1)
            while ope.find_image(work_image_path + 'collect_button.png') is not None:
                ope.click_image_path(work_image_path + 'collect_button.png')
                log.log('暗影天蛇boss已拾取')
                ope.click_image_path(work_image_path + 'close_windows.png')
                break
# break  # 结束循环"""
"""import run_logging as log


def pickup():
    work_image_path = 'image\\work\\'
    mon_image_path = 'image\\monitor\\'
    while ope.find_image(work_image_path + 'boss3.png') is not None:
        time.sleep(1)
        while ope.find_image(work_image_path + 'collect_button.png') is not None:
            ope.click_image_path(work_image_path + 'collect_button.png')
            log.log('暗影天蛇boss已拾取')
            ope.click_image_path(work_image_path + 'close_windows.png')
            ope.click_image_path(mon_image_path) + 'stationm.png'
            break

pickup()"""
"""




def pickup():
    # 检查是否有boss
    if ope.find_image(work_image_path + 'boss3.png') is not None:
        # 发送消息
        # msg.send_msg('天蛇boss')
        log.log('暗影天蛇boss已出现')
        # 切换总览
        # qqope.click_image(ope.find_image(work_image_path + 'overview_boss.png'))
        # ope.save_location(work_image_path + 'boss3.png')
        # ope.click_image(ope.find_image(mon_image_path + 'overview_work.png'))
        ope.click_with_key(work_image_path + 'boss3.png', 'q')
        ope.click_image_path(work_image_path + 'ab.png')
        ope.random_sleep(2, 1)
        ope.click_image_path(work_image_path + 'collect.png')
        ope.random_sleep(10, 2)
        # exit_inner_loop = False
        exit_outer_loop = False
        while ope.find_image(work_image_path + 'boss3.png') is not None:
            time.sleep(1)
            while ope.find_image(work_image_path + 'collect_button.png') is not None:
                ope.click_image_path(work_image_path + 'collect_button.png')
                log.log('暗影天蛇boss已拾取')
                ope.click_image_path(work_image_path + 'close_windows.png')
                ope.click_image_path(mon_image_path + 'stations.png')
                exit_outer_loop = True
                break
            if exit_outer_loop:
                break
        ope.click_with_key(mon_image_path + 'stations.png', 'd')
        ope.random_sleep(40, 5)
        ope.click_image(ope.find_image(work_image_path + 'collect.png'))
        ope.
pickup()"""

"""

ope.click_image_path(work_image_path + 'jump_to_station.png')
ope.random_sleep(40, 5)
ope.click_image(ope.find_image(work_image_path + 'collect.png'))
ope.click_position(700, 250)
ope.click_position(1000, 230)
time.sleep(3)
pyautogui.keyDown('ctrl')
pyautogui.keyDown('a')
time.sleep(0.5)
pyautogui.keyUp('a')
pyautogui.keyUp('ctrl')
pyautogui.dragTo(1300, 250, duration=1)
ope.click_image_path(work_image_path + 'trans_button.png')
ope.click_image_path(work_image_path + 'close_windows.png')"""
# import operate as ope
# work_image_path = 'pve\\image\\work\\'
# mon_image_path = 'pve\\image\\monitor\\'
# def check():
#     ope.find_image(work_image_path + "FFX.png")
#     ope.find_image(work_image_path + "DD.png")
#     ope.find_image(work_image_path + "BB.png")
#     ope.find_image(work_image_path + "BCP.png")
#     ope.find_image(work_image_path + "BC.png")
#     print(ope.find_image(work_image_path + "FFX.png"))
#     print(ope.find_image(work_image_path + "DD.png"))
#     print(ope.find_image(work_image_path + "BB.png"))
#     print(ope.find_image(work_image_path + "BCP.png"))
#     print(ope.find_image(work_image_path + "BC.png"))
#
#
# check()
